﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic.Web;
using LotteryVote.Entity.Enums;
using LotteryVote.Utility;
using System.Web.Security;

namespace LotteryVote
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindSelectedLanguage();
        }

        void BindSelectedLanguage()
        {
            var lang = base.GetCurrentLanguage();
            ddl_language.SelectedValue = lang;
        }

        protected void btn_login_Click1(object sender, EventArgs e)
        {
            string userName = txt_userName.Text.Trim();
            string password = txt_pwd.Text.Trim();
            bool isLogin = base.LoginFacade.Login(userName, password);
            if (isLogin)
                if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                    FormsAuthentication.RedirectFromLoginPage(userName, false);
                else
                    Response.Redirect("Default.aspx");
            else
            {

                string script = string.Format("showMessage(\"{0}\",\"{1}\");", GetLocalResourceObject("LoginFaild"), GetLocalResourceObject("UserNamePasswordFaild"));
                this.ClientScript.RegisterStartupScript(this.GetType(), "LoginError", script, true);
            }
        }

    }
}